
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>8.2.&nbsp;Database Modeling - Chapter&nbsp;8.&nbsp;Database Integration</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../load-jdbc/" title="8.1.&nbsp;Load JDBC"></link>
      <link rel="next" href="../mongodb/" title="8.4.&nbsp;Interacting with MongoDB"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../load-jdbc/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Load JDBC</a></span><span class="nav-current">
               <p class="nav-title hidden">8.2.&nbsp;Database Modeling</p></span><span class="nav-next"><a accesskey="n" href="../mongodb/">Interacting with MongoDB<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="database-modeling">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#database-modeling"></a>8.2.&nbsp;Database Modeling
                  </h2>
               </div>
            </div>
         </div>
         <p>This new package provides a set of function in order to extract metadata information from different data sources such as RDBMS,
            JSON file etc
         </p>
         <div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><code class="literal">apoc.model.jdbc('key or url', {schema:'&lt;schema&gt;', write: &lt;true/false&gt;, filters: { tables:[], views: [], columns: []}) YIELD
                     nodes, relationships</code>: load schema from relational databases
               </li>
            </ul>
         </div>
         <section class="section" id="_literal_apoc_model_jdbc_literal">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_literal_apoc_model_jdbc_literal"></a>8.2.1.&nbsp;<code class="literal">apoc.model.jdbc</code></h3>
                  </div>
               </div>
            </div>
            <p>The procedure allows to extract metadata information by any JDBC compatible db.</p>
            <section class="section" id="_configuration">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_configuration"></a>8.2.1.1.&nbsp;Configuration
                        </h4>
                     </div>
                  </div>
               </div>
               <div class="informaltable">
                  <div class="table" id="d0e9504">
                     <table class="informaltable" border="1">
                        <colgroup>
                           <col class="col_1"></col>
                           <col class="col_2"></col>
                           <col class="col_3"></col>
                        </colgroup>
                        <thead>
                           <tr>
                              <th style="text-align: left; vertical-align: top; ">Config</th>
                              <th style="text-align: left; vertical-align: top; ">Type</th>
                              <th style="text-align: left; vertical-align: top; ">&nbsp;Description</th>
                           </tr>
                        </thead>
                        <tbody>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">schema</code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">String. Default <code class="literal">empty</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>The schema name.</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">write</code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">boolean. Default <code class="literal">false</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>If you want persist the data on Neo4j</p>
                              </td>
                           </tr>
                           <tr>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>filters</p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p><code class="literal">map&lt;String, Array&lt;String&gt;&gt;. Default <code class="literal">empty</code></code></p>
                              </td>
                              <td style="text-align: left; vertical-align: top; ">
                                 <p>A set of filters for each object type <code class="literal">tables</code>, <code class="literal">views</code>, <code class="literal">columns</code></p>
                              </td>
                           </tr>
                        </tbody>
                     </table>
                  </div>
               </div>
               <section class="section" id="_filters">
                  <div class="titlepage">
                     <div>
                        <div>
                           <h5 class="title"><a class="anchor" href="#_filters"></a>Filters
                           </h5>
                        </div>
                     </div>
                  </div>
                  <div class="informaltable">
                     <div class="table" id="d0e9570">
                        <table class="informaltable" border="1">
                           <colgroup>
                              <col class="col_1"></col>
                              <col class="col_2"></col>
                              <col class="col_3"></col>
                           </colgroup>
                           <thead>
                              <tr>
                                 <th style="text-align: left; vertical-align: top; ">Config</th>
                                 <th style="text-align: left; vertical-align: top; ">Type</th>
                                 <th style="text-align: left; vertical-align: top; ">&nbsp;Description</th>
                              </tr>
                           </thead>
                           <tbody>
                              <tr>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">tables</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">Array&lt;String&gt;</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p>A set of regex patterns that, if matched, exclude the tables</p>
                                 </td>
                              </tr>
                              <tr>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">views</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">Array&lt;String&gt;</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p>A set of regex patterns that, if matched, exclude the views</p>
                                 </td>
                              </tr>
                              <tr>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">columns</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p><code class="literal">Array&lt;String&gt;</code></p>
                                 </td>
                                 <td style="text-align: left; vertical-align: top; ">
                                    <p>A set of regex patterns that, if matched, exclude the columns</p>
                                 </td>
                              </tr>
                           </tbody>
                        </table>
                     </div>
                  </div>
               </section>
            </section>
            <section class="section" id="_example_3">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_example_3"></a>8.2.1.2.&nbsp;Example
                        </h4>
                     </div>
                  </div>
               </div>
               <p>Starting from the following schema:</p><pre class="programlisting highlight"><code data-lang="sql"> CREATE TABLE "country" (
   "Code" CHAR(3) NOT NULL DEFAULT '',
   "Name" CHAR(52) NOT NULL DEFAULT '',
   "Continent" enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
   "Region" CHAR(26) NOT NULL DEFAULT '',
   "SurfaceArea" FLOAT(10,2) NOT NULL DEFAULT '0.00',
   "IndepYear" SMALLINT(6) DEFAULT NULL,
   "Population" INT(11) NOT NULL DEFAULT '0',
   "LifeExpectancy" FLOAT(3,1) DEFAULT NULL,
   "GNP" FLOAT(10,2) DEFAULT NULL,
   "GNPOld" FLOAT(10,2) DEFAULT NULL,
   "LocalName" CHAR(45) NOT NULL DEFAULT '',
   "GovernmentForm" CHAR(45) NOT NULL DEFAULT '',
   "HeadOfState" CHAR(60) DEFAULT NULL,
   "Capital" INT(11) DEFAULT NULL,
   "Code2" CHAR(2) NOT NULL DEFAULT '',
   PRIMARY KEY ("Code")
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 CREATE TABLE "city" (
   "ID" INT(11) NOT NULL AUTO_INCREMENT,
   "Name" CHAR(35) NOT NULL DEFAULT '',
   "CountryCode" CHAR(3) NOT NULL DEFAULT '',
   "District" CHAR(20) NOT NULL DEFAULT '',
   "Population" INT(11) NOT NULL DEFAULT '0',
   PRIMARY KEY ("ID"),
   KEY "CountryCode" ("CountryCode"),
   CONSTRAINT "city_ibfk_1" FOREIGN KEY ("CountryCode") REFERENCES "country" ("Code")
 ) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1;

 CREATE TABLE "countrylanguage" (
   "CountryCode" CHAR(3) NOT NULL DEFAULT '',
   "Language" CHAR(30) NOT NULL DEFAULT '',
   "IsOfficial" enum('T','F') NOT NULL DEFAULT 'F',
   "Percentage" FLOAT(4,1) NOT NULL DEFAULT '0.0',
   PRIMARY KEY ("CountryCode","Language"),
   KEY "CountryCode" ("CountryCode"),
   CONSTRAINT "countryLanguage_ibfk_1" FOREIGN KEY ("CountryCode") REFERENCES "country" ("Code")
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;</code></pre><p>By doing this procedure call:</p>
               <p><code class="literal">call apoc.model.jdbc('jdbc:mysql://mysql:3306', {schema: 'test', credentials: {user: 'root', password: 'andrea'}})</code></p>
               <p>You&#8217;ll get the following result:</p>
               <div class="informalfigure">
                  <div class="mediaobject"></div>
               </div>
            </section>
         </section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>